#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright @ 2014 OPS, Qunar Inc. (qunar.com)
#
# Author: tingfang.bao <tingfang.bao@qunar.com>
# DateTime: 15-3-10 下午2:19
from subdomain_dispatcher import SubdomainDispatcher
from werkzeug.serving import run_simple
from flask import Flask, Blueprint, current_app

bp = Blueprint("bp", __name__, url_prefix="/")


@bp.route('/', methods=['GET', 'POST'])
def index():
    return 'bp index:' + current_app.config['domain']


def create_app(domain):
    app = Flask(__name__)
    app.config['domain'] = domain

    app.register_blueprint(bp)
    return app


application = SubdomainDispatcher("qunar.com", create_app)

if __name__ == '__main__':
    run_simple('0.0.0.0', 8080, application, use_reloader=True, use_debugger=True, use_evalex=True)

